import org.apache.commons.io.FileUtils;
import org.springframework.util.FileCopyUtils;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>Title: Test2</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2019</p>
 * <p>Company: www.ctl.com</p>
 *
 * @author ctl
 * @version 1.1
 * @date 2022-06-02 14:20
 */
public class Test2 {
    public static void main(String[] args) {
        String path = "/home/ctl/Downloads/wise_base_common";
        File file = new File(path);
        File[] files = file.listFiles();
        List<String> list = new ArrayList<>();
        for (int i = 0; i < files.length; i++) {
            try {
                List<String> strings = FileUtils.readLines(files[i], "utf-8");
                if (i == 0) {
                    for (int i1 = 0; i1 < strings.size(); i1++) {
                        if ("<a href=\"#header\"><p class=\"normal\">Back</a>".equals(strings.get(i))) {
                            break;
                        } else {
                            list.add(strings.get(i));
                        }
                    }
                }
                if (i > 0 && i < files.length - 1) {
                    boolean start = false;
                    for (int i1 = 0; i1 < strings.size(); i1++) {
                        if ("<body bgcolor='#ffffff' topmargin=\"0\">".equals(strings.get(i1))) {
                            start = true;
                        }
                        if ("<a href=\"#header\"><p class=\"normal\">Back</a>".equals(strings.get(i))) {
                            break;
                        }
                        if (start) {
                            list.add(strings.get(i1));
                        }
                    }
                }
                if (i == files.length - 1) {
                    boolean start = false;
                    for (int i1 = 0; i1 < strings.size(); i1++) {
                        if ("<body bgcolor='#ffffff' topmargin=\"0\">".equals(strings.get(i1))) {
                            start = true;
                        }

                        if (start) {
                            list.add(strings.get(i1));
                        }
                    }
                }
            } catch (IOException e) {

            }
        }
        try {
            FileUtils.writeLines(new File("/home/ctl/Downloads/wise_base_common/all.html"),list);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
